package net.playcabbage.rest;

import java.sql.SQLException;
import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;

import cabbage.database.idao.ICheckinDAO;
import cabbage.database.operations.CheckinDAO;


@Path("/checkins")
public class CheckinService {

	@GET
	@Path("/getjson")
	@Produces(MediaType.APPLICATION_JSON)
	public JSONArray getGridCellList() throws NamingException, SQLException, JSONException  {
//		Cupcake cupcake = new Cupcake();
		ICheckinDAO checkin = new CheckinDAO();
		JSONArray j = checkin.getLastCheckins();
//		JSONArray j = cupcake.getCheckinBeanJSONArray2(); 
		return j;
	}
	
	@GET
	@Path("/getjson/bla")
	public String getStuff(@QueryParam("playerid") int playerid) throws NamingException, SQLException, JSONException  {
//		Cupcake cupcake = new Cupcake();
//		JSONArray j = cupcake.getCheckinBeanJSONArray2(); 
//		System.out.println(j);
	     System.out.println(Integer.toString(playerid));
		return Integer.toString(playerid);
	}
	


	@POST
	@Path("/post")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response createTrackInJSON(String stringx) {
		String result = "Mah String is... : " + stringx;
		return Response.status(201).entity(result).build();
	}

}
